#include "Computer.h"
#include <iostream>

using std::cout;
using std::endl;

#if 0
Computer gComputer("huawei", 8000);//全局对象

void test()
{
    Computer com("ThinkPad", 5300);//栈对象
    cout << "com = ";
    com.print();

    /* com.~Computer();//析构函数可以显示调用，但是不建议显示调用 */
    /* com.print(); */

    cout << endl << endl;
    int *pInt = new int(10);

    Computer *pc = new Computer("xiaomi", 6000);//堆对象
    pc->print();

    delete pc;//堆对象需要显示的使用delete，否则析构函数调用不到
    pc = nullptr;

    delete pInt;
    pInt = nullptr;

}

int test2()
{
    gComputer.print();
    cout << endl;
    cout << "begin main..." << endl;
    test();
    cout << "finish main..." << endl;

}
#endif

void test3()
{
    Computer com1("ThinkPad", 5300);
    cout << "com1 = ";
    com1.print();

    cout << endl;
    Computer com2 = com1;
    cout << "com2 = ";
    com2.print();

    cout << endl;
    com1.setBrand("huawei");
}

void test4()
{
    Computer com1("ThinkPad", 5300);
    cout << "com1 = ";
    com1.print();

    cout << endl;
    Computer com2("huawei", 8000);
    cout << "com2 = ";
    com2.print();

    cout << endl;
    com2 = com1;//赋值
    cout << "com1 = ";
    com1.print();
    cout << "com2 = ";
    com2.print();

    cout << endl << "com1赋值给com1" << endl;
    com1 = com1;//自己赋值给自己
    cout << "com1 = ";
    com1.print();
}

void test5()
{
    int a = 0;
    cout << "sizeof(int) = " << sizeof(int) << endl;
    cout << "sizeof(Computer) = " << sizeof(Computer) << endl;

    cout << endl << "在购买电脑之前，电脑总价是:" << endl;
    Computer::printTotalPrice();

    cout << endl;
    Computer com1("ThinkPad", 5300);
    cout << "com1 = ";
    com1.print();
    cout << "购买第一台电脑的总价: " << endl;
    com1.printTotalPrice();
    Computer::printTotalPrice();//ok,可以使用类型与作用域限定符
    /* Computer::print();//error */

    cout << endl;
    Computer com2("huawei", 8000);
    cout << "com2 = ";
    com2.print();
    cout << "购买第二台电脑的总价: " << endl;
    com2.printTotalPrice();
    com1.printTotalPrice();
    Computer::printTotalPrice();
}

void test6()
{
    //1、非const的对象默认情况调用的是非const版本的成员函数；而
    //const对象调用是const版本的成员函数
    //
    //2、非const对象也是可以调用const版本的成员函数的
    //3、const对象是不能调用非const版本的成员函数
    /* const int number = 10; */
    Computer com1("ThinkPad", 5300);
    cout << "com1 = ";
    com1.print();

    cout << endl;
    const Computer com2("huawei", 8000);
    cout << "com2 = ";
    com2.print();
}

int main(int argc, char **argv)
{
    test6();
    return 0;
}
